import axios from "axios";
import store from "@/store"
import router from '@/router'

//本地
// axios.defaults.baseURL="http://127.0.0.1:8888/api/private/v1/"
//线上
axios.defaults.baseURL="http://82.156.30.240:8888/api/private/v1/"

//请求前 拦截
axios.interceptors.request.use(function (config) {
    // Do something before request is sent
 config.headers.Authorization=store.getters.token
        // 发送 请求头 token
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
    
  });

  // 响应拦截
// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Do something with response data
    if (response.data.meta.status == 400) {
      router.push("/login")
      store.commit("user/DEL_TOKEN")
      store.commit("user/DEL_USERNAME")
  
    }
    return response.data;
  }, function (error) {
    // Do something with response error
    return Promise.reject(error);
  });


export default axios;